<template>
  <EvDialog
    title="选择人员"
    :dialogVisible="dialogVisible"
    width="45%"
    :close-on-click-modal="false"
    :modal-append-to-body="false"
    :append-to-body="true"
    @handleClose="handleDialogClose"
    @handleCancel="handleDialogCancel"
    @handleConfirm="handleDialogConfirm"
  >
    <EvTable
      ref="reciverGroupTable"
      :options="{ data, columns, height: '470', toolbarConfig: { custom: false } }"
      :tablePage="page"
      @handlePageChange="handlePageChange"
    >
    </EvTable>
  </EvDialog>
</template>
  <script>
import EvDialog from "@/components/EvDialog/index.vue";
export default {
  components: {
    EvDialog,
  },
  data() {
    return {
      dialogVisible: false,
      page: {
        currentPage: 1,
        pageSize: 10,
        total: 0,
      },
      data: [],
      columns: [
        { type: "checkbox", fixed: "left", align: "center", width: 50 },
        { title: "序号", fixed: "left", align: "center", width: 60, type: "seq" },
        // {
        //   title: "部门",
        //   field: "department.title",
        // },
        // { title: "名称", field: "data.name" },
        {
          title: "姓名",
          field: "name",
        },
        { title: "编号", field: "code" },
      ],
    };
  },
  methods: {
    // 加载数据
    loadData() {
      this.$server()
        .query(
          "function-user",
          "User",
          {
            AND: [["isDelete", "=", 0]],
          },
          "insertTime desc",
          { current: this.page.currentPage, size: this.page.pageSize },
          true
        )
        .then((response) => {
          this.page.total = response.total;
          this.data = response.list;
        })
        .catch((response) => {
          this.$message.error(response.data.message);
        });
    },
    open() {
      this.loadData();
      this.dialogVisible = true;
    },
    handleDialogCancel() {
      this.dialogVisible = false;
    },
    handleDialogClose() {
      this.dialogVisible = false;
    },
    handleDialogConfirm() {
      let record = this.$refs.reciverGroupTable.getSelectRecords();
      if (record && record.length == 0) {
        this.$message.warning("请选择");
        return;
      }
      this.dialogVisible = false;
      this.$emit("handleSelectBack", record);
    },
    handlePageChange({ currentPage, pageSize }) {
      this.page.currentPage = currentPage;
      this.page.pageSize = pageSize;
      this.loadData();
    },
  },
};
</script>
  <style lang="scss" scoped></style>
  